Main module implementation description
In the main module, all necessary state, state transition, error and function handling facilities are implemented for this level.
Context diagram for the main module
The following objects (variables, tasks...) are defined in the structure of the main module.
M1_CmdState
Description
This internal word variable contains the actual state command value. It is automatically set to state 'Standby' during power up.
//********************************************* //** State Defines ** //********************************************* #define DEF_StateUndefined 0 #define DEF_StateStandby 1 #define DEF_StateManual 2 #define DEF_StateAutomatic 3 #define DEF_StateBusy 4 #define DEF_StateErrorFatal 6
|
Usage
These state commands are usually set in the communication interface (see software listing of ACT_M1_Translate and ACT_M1_SimaticSimu) and must not be set directly from the host system. If additional or different state commands are needed, then the definitions described above can be modified accordingly.
M1_AckState
Description
This internal word variable contains the actual state acknowledge value, as a result from the M1_CmdState state command performed with success. Possible values are the same as for the state commands (see above).
Usage
Out of this value the corresponding acknowledgements for the PLC"Programmable Logic Controller" A Programmable Logic Controller, PLC, or Programmable Controller is a digital computer used for automation of industrial processes, such as control of machinery on factory assembly lines. Used to synchronize the flow of inputs from (physical) sensors and events with the flow of outputs to actuators and events can be created in the communication interface.
M1_ReqState
Description
This internal word variable contains the internally active state. It is used for internal purpose only, to keep the actual state value, e.g. while performing a function. Possible values are the same as for the state commands (see above).
Usage
Used by system, do not use it for application purpose.
Description
This internal word variable contains the actual module status and error information. It is automatically set to the default value during power up. The meaning of the predefined Module Error Bits are as follows:
Bit 15 |
Bit 14 |
Bit 13 |
Bit 12 |
Bit 11 |
Bit 10 |
Bit 9 |
Bit 8 |
Bit 7 |
Bit 6 |
Bit 5 |
Bit 4 |
Bit 3 |
Bit 2 |
Bit 1 |
Bit 0 |
Bits |
Description |
0 |
error stop reported by drive (drive error) |
1 |
error fatal reported by Drive (lag error) |
2 |
not used (motor temperature too high) |
3 |
not used (external stop) |
4 |
not used (negative limit switch reached) |
5 |
not used (positive limit switch reach) |
6 |
not used (not used) |
7 |
not used (not used) |
8 |
not used (state HW enable) |
9 |
not used (state AS enable) |
10 |
not used (axis is powered on) |
11 |
not used (axis is homed) |
12 |
not used (axis is running) |
13 |
not used (pipe is connected) |
14 |
error stop (error stop) |
15 |
error fatal (error fatal) |
Usage
While the error bits are usually set only by the error handling (M1_ErrorHandling), the mode bits can be modified where ever needed in the application program (except in the interface). Several bits can be set at the same time. Several masks have been defined to test or modify the whole word. For each module, there is one mask to define the bits causing a fatal error (e.g. MSK_M1_StatusErrorFatal) and one for the stop error (e.g. MSK_M1_StatusErrorStop). To add errors and modes, the bits not already assigned by default can be used (i.e. bits 16 to 31).
bErrorReset
Description
This internal flag variable is used as the error reset command for the main and axis modules. It is reset during power up.
Usage
Set and reset this flag to activate a reset of the module errors (M1_StatusWord, Ai_StatusWord).
M1_ErrorHandling
Description
This program is responsible for the main module error handling. If an error occurs (in the main module or a submitted axis module), the corresponding bit in the module status (M1_StatusWord) is set. This causes the error reaction bits (MSK_Mi_StatusErrorStop, MSK_Mi_StatusErrorFatal) to be set in the module status word.
Usage
Any additional error which needs to be treated has to be included in this program. Do not forget to modify the corresponding masks (MSK_M1_StatusErrorFatal, MSK_M1_StatusErrorStop) to cause the correct reaction on errors.
M1_ModuleController
Description
This program is the heart of the whole controller and contains:
- a state manager sequence
- all state sequences
- and state dependent function sequences of the main module
Usage
Some rules have to be followed, when using and changing states and functions (see also How to add a new state and How to add a new function).